#pragma once

#include "exports.hpp"
#include "DataProvider.h"




/**
 * The QueueProvider is a special implementation that stores all replies in memory in
 * a multiple reader/multiple writer queue, with the addition of storing
 * replies in memory, in case the queue gets too big.
 */
class CRAWLER_API QueueProvider
	: public DataProvider
{
public:

	typedef boostext::queue<Reply>          ReplyQueue;
	typedef ReplyQueue::unbuffered_reader   ReplyQueueReader;
	typedef ReplyQueue::unbuffered_writer   ReplyQueueWriter;

private:

	ReplyQueue              m_queue;
	ReplyQueueReader        m_reader;
	ReplyQueueWriter        m_writer;

public:

	QueueProvider();
	virtual ~QueueProvider();



	/**
	 * Returns the next reply (if available).
	 * If no reply is returned, then the DataProvider shall wait for
	 * several seconds, before trying again.
	 *
	 * This function is thread-safe.
	 */
	virtual Reply::Opt next();

	/**
	 * Inserts this reply into the DataProvider.
	 */
	virtual void insert(const Reply& reply);
};
///////////////////////////////////////////////////////////////////////////////////////////////////
